package com.borqsprocessmanager.info;

import com.borqsprocessmanager.util.Log;

public class BatteryTaskInfo {
    private final String TAG = "BatteryAlsInfo";

    public static final int WIFI = 0;
    public static final int MOBILE = 1;
    public static final int NORMAL = 2;
    public static final int WIFI_MOBILE = 3;
    public static final int WIFI_NORMAL = 4;

    BaseBatteryAlsInfo pre;
    BaseBatteryAlsInfo cur;

    public BaseBatteryAlsInfo getInfo(int state) {
        if (cur == null) {
            Log.v(TAG, "cur == null");
            pre = cur = createBatteryInfo(state);
            Log.v(TAG, "cur == null___" + cur.type);
        } else {
            if (cur.type != state) {
                Log.v(TAG, "cur.type != state___cur.type===" + cur.type
                        + "___state===" + state);
                if (pre.type != state) {
                    Log.v(TAG, "pre.type != state___cur.type===" + pre.type
                            + "___state===" + state);
                    pre.saveArgTimeMToFile();
                    pre = createBatteryInfo(state);
                }
                BaseBatteryAlsInfo temp = cur;
                cur = pre;
                pre = temp;
            }
        }
        Log.v(TAG, "getInfo___" + cur.type);
        Log.v(TAG, "getgetFileName___" + cur.getFileName());
        Log.v(TAG, "getgetFileName___" + cur.getSharfreKey());
        Log.v(TAG, "getgetFileName___" + cur.getArgTimeM());
        return cur;
    }

    public void saveDataToFile() {
        Log.v(TAG, "saveDataToFile");
        if (pre != null) {
            pre.saveArgTimeMToFile();
            cur.saveArgTimeMToFile();
        }
    }

    private BaseBatteryAlsInfo createBatteryInfo(int state) {
        BaseBatteryAlsInfo info = null;
        Log.v(TAG, "createBatteryInfo===" + state);
        switch (state) {
        case WIFI:
            info = new WifiBatteryAlsInfo(state);
            break;
        case MOBILE:
            info = new MobileBatteryAlsInfo(state);
            break;
        case NORMAL:
            info = new NormalBatteryAlsInfo(state);
            break;
        case WIFI_MOBILE:
            info = new WifiIDELMobileAlsInfo(state);
            break;
        case WIFI_NORMAL:
            info = new WifiIDELNormalAlsInfo(state);
            break;
        default:
            break;
        }
        return info;
    }
}
